package com.mc2.docapp.disabilityassessmenttool.utils;

import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.mc2.docapp.disabilityassessmenttool.AdditionalInfo;

import java.util.HashSet;

public class Statics {
    public static Class<?> router(Class<?> aClass) {
        int i = 0;
        try {
            for (i = (AdditionalInfo.routerList.size() - 1); i >= 0 ; i--) {
                if (AdditionalInfo.routerList.get(i).equals(aClass)) {
                    System.out.println("##  from -> "+aClass+"   to -> "+AdditionalInfo.routerList.get(i + 1));
                    return AdditionalInfo.routerList.get(i + 1);
                }
            }
        } catch (Exception v) {
            System.out.println(v.getMessage());
        }
        return aClass;
    }

    public static synchronized HashSet<EditText> getEditTexts(ViewGroup root, HashSet<EditText> views) {
        for (int i = 0; i < root.getChildCount(); i++) {
            View v = root.getChildAt(i);
            if (v instanceof EditText) {
                views.add((EditText) v);
            } else if (v instanceof ViewGroup) {
                views.addAll(getEditTexts((ViewGroup) v, views));
            }
        }
        return views;
    }
}
